<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    request.setCharacterEncoding("UTF-8");
    String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";
%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/JSP/backHome/modalWindows/StudentsListPage.jsp" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript" src="<%=path%>/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="<%=path%>/HoganJS/handlebars-v4.0.11.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=path%>/CSS/bombBox.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/CSS/backLayout.css">
    <style type="text/css">
        input {
    	width: 230px;
		}
		.modal-data1 {
			  visibility: hidden; 
			  z-index: 1001;
			  width: 1000px;
			  min-height: 500px;
			  margin: 100px auto;
			  background-color: #FFFFFF;
			 /* border: 1px solid #C80B14;*/
			 -moz-box-shadow:0 10px 20px #8AC1E2 inset,0 -10px 0 #57a0ff inset;
        	 -webkit-box-shadow:0 10px 20px #8AC1E2 inset,0 -10px 0 #57a0ff inset;
      /*         box-shadow:0 0 10px #cccccc; 
			  box-shadow: #cccccc; */
			  box-shadow: 0 10px 20px #57a1ff inset,0 -10px 0 #57a0ff inset;
			  padding: 5px;
			  text-align: center;
			  position: fixed;
			  left: 22%;
		}
		
		.modal-data1 td{padding-left: 15px;padding-right: 15px}
		.modal-data1 tr:FIRST-CHILD td{padding: 0px 10px;}
		.modal-data1 tr{padding-top: 30px}
		.modal-data1 form table {
			margin: 0px
		}
		.div_input_hang {
			width: 100%;
			height: 40px;
		}
		.input_hang {
			float: left;
			width: 500px;
			height: 40px;
		}
    </style>
</head>
<body style="background: #f5f5f5">
<div class="main">
    <div class="weizhi">
        车辆管理>>加油卡充值>>新增
    </div>
    <div class="div_body" style="box-shadow: 0 0 5px #cccccc;">
        <div id="modal-overlay">
        </div>
			<div class="modal-data1" >
				<div style="height: 60px">
				 <ul>
				  	<li  style="text-align: left;margin-left: 60px;height: 40px;line-height: 40px">
				  		<span>名称：</span>
				  		<span>
				  		 	<input class="name" type="text"  value="">
				  		</span>
				  		<span>
				  			<button class="findBtn1">
				  				查询
				  			</button>
				  		</span>
				  	</li>
				 </ul>
				</div>
				<div style="width:1000px; height:350px; overflow:scroll;">
			      <form action="">
			        <table class="head1"  style="width: auto;white-space:nowrap;border-spacing:0px">
			        <tr style="background: #f2f2f2;height: 30px;line-height: 20px;" class="sel">
			        <td style="width: 20px"></td> 
			        <td>
			        	名称
			        </td>
			        <td>
			        	编码
			        </td>
			        <td>
			        	简称
			        </td>
			        <td>
			        	描述
			        </td>			       
			        <td>
			        	创建时间
			        </td>
			        <td>
			        	用户名
			        </td>
			        <td>
			        	别名
			        </td>
			        <td>
			        	最后修改时间
			        </td>
			        <td>
			        	财务组织
			        </td>
			        <td>
			        	余额
			        </td>			      		       			       
			        </tr>
			        <c:forEach items="${fillingCardList }" var="fillingCard">
			        	<tr class="fillingCard">
			        		<td><input style="width: 20px;" type="checkbox" class="check" name="fillingCard" value="${fillingCard.fid }"/></td>
			        		<td>${fillingCard.fnameL2 }</td>
			        		<td>${fillingCard.fnumber }</td>
			        		<td>${fillingCard.fsimplename }</td>
			        		<td>${fillingCard.fdescriptionL2 }</td>
			        		<td>${fillingCard.fcreatetime }</td>
			        		<td>${fillingCard.createName }</td>
			        		<td>${fillingCard.createName }</td>
			        		<td>${fillingCard.flastupdatetime }</td>
			        		<td>${fillingCard.cfficompanyName }</td>
			        		<td>${fillingCard.cfamount }</td>
			        	</tr>
			        </c:forEach> 			        
			        </table>
			      </form>
                    <button class="subtn1"
                            style="width: 150px;position: absolute;bottom: 25px;font-size: 16px;left: 280px">
			      	确定
			      </button>
                    <button class="btn"
                            style="width: 150px;position: absolute;bottom: 25px;font-size: 16px;right: 280px">
			      	关闭
			      </button>
			     </div>			    
			</div>
        
        <div class="div_form">
            <form action="<%=path%>/DrivingSys/addFillingCardRecharge"  class="form" method="post" onsubmit="return check()">
                <input id="fid" type="text" name="fid" style="visibility:hidden" value=""/>
                <div class="jczl">
                 <div class="div_input_hang">
						<div class="input_hang">
							<span class="gn_name">驾校&nbsp;:&nbsp;</span>
							<input type="hidden" name="fcontrolunitid" value="${department.fid }">
							<input  type="text" name="drivingSchool"  value="${department.fnameL2}" readonly="readonly" style="color: gray;"/>
						</div>				
					</div>
					<div class="div_input_hang">
						<div class="input_hang">
							<span class="gn_name">单据编号&nbsp;:&nbsp;</span>
							<input  type="text" class="fnumber" name="fnumber"   value="${fnumber }"  readonly="readonly"/>
						</div>							
					</div>
					<div class="div_input_hang">
						<div class="input_hang">						
							<span class="gn_name">业务日期&nbsp;:&nbsp;</span>
							<input type="text" name="fbizdate"  value="${time}" id="fbizdate"
                               onclick="WdatePicker({el:'fbizdate',dateFmt:'yyyy-MM-dd'})"/>                        	
                        	<img onclick="WdatePicker({el:'fbizdate',dateFmt:'yyyy-MM-dd'})"
                             src="<%=path%>/image/date.jpg" align="absmiddle" style="padding-left: 15px">
						</div>									
					</div>
					<div class="div_input_hang">
						<div class="input_hang">
							<span class="gn_name">金额&nbsp;:&nbsp;</span>
							<input  type="text" name="cfamount"  class="cfamount" value=""  onblur="cfamount3($(this))"/>
						</div>					
					</div>
					<div class="div_input_hang">
						<div class="input_hang">
							<span class="gn_name">备注&nbsp;:&nbsp;</span>
							<input  type="text" name="fdescription"  class="fdescription" value=""  />
						</div>											
					</div>
					<div class="div_input_hang">
						<div class="input_hang">
							<span class="gn_name">单据状态&nbsp;:&nbsp;</span>
							<select name="cfbillstate"   style="width: 234px;height: 31px;color: gray;">
								<option value="3">新增</option>
							</select>
						</div>											
					</div>
					<div class="div_input_hang">
						<div class="input_hang">
							<span class="gn_name">加油卡&nbsp;:&nbsp;</span>
							<input type="text" name="cfrefuelName" value=""  class="cfrefuelName is_click_ne "/>
							<input type="hidden" name="cfrefuelid" value=""  class="cfrefuelid"/>
						</div>											
					</div>
					<div class="div_input_hang">
						<div class="input_hang">
							<span class="gn_name">审核人&nbsp;:&nbsp;</span>
							<input type="text" name="checkName" value=""  class="checkName" disabled="disabled"/>							
						</div>											
					</div>
					<div class="div_input_hang">
						<div class="input_hang">
							<span class="gn_name">创建人&nbsp;:&nbsp;</span>
							<input type="text" name="createName" value="${user.name }"  class="createName" disabled="disabled"/>							
						</div>											
					</div>
					<div class="div_input_hang">
						<div class="input_hang">
							<span class="gn_name">创建时间&nbsp;:&nbsp;</span>
							<input type="text" name="fcreatetime" value=""  class="fcreatetime" disabled="disabled"/>							
						</div>											
					</div>
                <div class="div_tj" style="margin-left: 110px; margin-top: 20px;">
                    <div>
                        <input type="submit" class="input_submit bc" value="" style="margin-top: 0px;margin-right: 30px;">
                    </div>
                    <div>
                        <input type="button" class="input_back fh" value="" onclick="back()" style="margin-top: 0px;"/>
                    </div>
                </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="<%=path%>/JQuery/jquery-1.8.2.js"></script>
<%@ include file="/WEB-INF/JSP/ajax.jsp" %>

<script>

    $(document).ready(function () {
        var type = "${type}";
        if (type == "1") {
            //alert("添加成功!");
			editAlert();
        }
    })

//弹出模式框
$(".cfrefuelName").click(function (){
	$('#modal-overlay').css('visibility', 'visible')
    $('.modal-data1').css('visibility', 'visible')
   	$('input:checkbox[name=fillingCard]').removeAttr('checked');
})
//关闭模式框
$(".btn").click(function (){
	$('#modal-overlay').css('visibility', 'hidden')
    $('.modal-data1').css('visibility', 'hidden')
   	$('input:checkbox[name=fillingCard]').removeAttr('checked');
})
//设置只能单选
$(".fillingCard td").live('click',function(){
    $('input:checkbox[name=fillingCard]:checked').each(function(i) {
    	$(this).removeAttr("checked");
     });
     $(this).parent().find("input:checkbox[name=fillingCard]").attr('checked','checked');
}) 
//双击确认
$(document).on('dblclick','.fillingCard td',function(){	
	var fid = '';//加油卡id
	var cardName='';//加油卡名称
	fid = $(this).parent().find("td").eq("0").find("input:checkbox[name=fillingCard]:checked").val()
	cardName = $(this).parent().find("td").eq("1").html()
	$(".cfrefuelName").val(cardName);
	$(".cfrefuelid").val(fid);
	$('#modal-overlay').css('visibility', 'hidden')
    $('.modal-data1').css('visibility', 'hidden')
   	$('input:checkbox[name=fillingCard]').removeAttr('checked');
})
//查询
$(".findBtn1").click(function (){
	var name = $(".name").val()
    $.ajax({
        url: '<%=path%>/DrivingSys/selFilingCardByName',
        type: "post",
        data: {'fnameL2': name},
        dataType: "json",
        success: function (json) {
            $(".head1 tr").not(':eq(0)').remove()
        	if(json.length== 0){
        		var nostr='<tr><td style="width: 30px;"></td><td colspan="5">抱歉，没有相关数据,请重新输入需要查找的名称！</td></tr>'
        			$(".head1").append(nostr)
        	}else{  
        		var str='';
        		for (var i = 0; i < json.length; i++) {
					if(json[i].fsimplename == null ){
                        json[i].fsimplename ="";
					}
					if(json[i].fdescriptionL2 == null ){
                        json[i].fdescriptionL2 = "";
					}
        			str+='<tr class="fillingCard"><td style="width: 20px;" class="td"><input style="width: 20px;" type="checkbox" name="fillingCard" value="'+json[i].fid+'" ></td>';
        			str+='<td>'+json[i].fnameL2+'</td><td>'+json[i].fnumber+'</td><td>'+json[i].fsimplename  +'</td><td>'+json[i].fdescriptionL2+'</td>'
        			str+='<td>'+json[i].fcreatetime+'</td><td>'+json[i].createName+'</td>'
        			str+='<td>'+json[i].createName+'</td><td>'+json[i].flastupdatetime+'</td><td>'+json[i].cfficompanyName+'</td>'
        			str+='<td>'+json[i].cfamount+'</td></tr>';
				}
        		$(".head1").append(str)	            		
        	}
        	
        },
        error: function () {
            alert('Error');
        }
    });  
})
//确认把加油卡信息填入
$(".subtn1").click(function (){
	var fid = '';//加油卡id
	var cardName='';//加油卡名称
	$("input:checkbox[name=fillingCard]:checked").each(function (i){
		fid = $(this).val();
		cardName =$(this).parent().parent().find("td").eq("1").html();
	})	
	if( fid == '' || cardName == ''){
		alert("请勾选加油卡！")
		return false;
	}
	$(".cfrefuelName").val(cardName);
	$(".cfrefuelid").val(fid);
	$('#modal-overlay').css('visibility', 'hidden')
    $('.modal-data1').css('visibility', 'hidden')
   	$('input:checkbox[name=fillingCard]').removeAttr('checked');
})
function check(){
	if($("#fbizdate").val() == null || $("#fbizdate").val() == ''){//业务日期不能为空
		alert("业务日期不能为空!")
		$("#fbizdate").focus();
		return false;
	}
    var cfrefuelid =$("input:hidden[name=cfrefuelid]").val();
    if(cfrefuelid == null || cfrefuelid ==""){
        alert("加油卡不能为空")
        return false;
    }
    $("input[type='submit']").attr("disabled", "disabled");
}
    //键盘事件
    $(".cfamount").live('keyup', function(event) {
        //最后一位是小数点的话，移除
        var $amountInput = $(this);
        //响应鼠标事件，允许左右方向键移动
        event = window.event || event;
        if(event.keyCode == 37 | event.keyCode == 39) {
            return;
        }
        //先把非数字的都替换掉，除了数字和.
        $amountInput.val($amountInput.val().replace(/[^\-?\d.]/g, "").
        //只允许一个小数点
        replace(/^\./g, "").replace(/\.{2,}/g, ".").
        //只能输入小数点后两位
        replace(".", "$#$").replace(/\./g, "").replace("$#$", ".").replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'));
    });
//返回
function back(){
    parent.closeSelectCard()

    //location = '<%=path%>/DrivingSys/queryFillingCardRecharge/look.action';
} 
function cfamount3(obj) {
	if(isNaN(Number(obj.val()))){
        obj.val("")
	}
}

</script>
</html>